/*  
 *@悦福利
 *@author zeng sheng
 *@date 2019/04/26
 */
layui.define(['form', 'table'], function(experts) {
    var form = layui.form,
        table = layui.table,
        $ = layui.$;

    this.yuefuli = {};
    yuefuli.goods = {
        categories: {
            is: undefined
            ,when: function(when) {
                this.is = when();
                return this;
            }
            ,render: function(api) {
                var render = function(selector, pid) {
                   layui.$.getJSON(api+'&pid='+pid , function(result) {
                        var html = '<option value="0">请选择</option>';
                        for (var i in result.data) {
                            html += '<option value="'+result.data[i].id+'-'+result.data[i].code+'">'+result.data[i].name+'</option>'
                        }
                        $(selector).html(html);
                        form.render('select');
                   });
                };

                if (typeof this.is === 'undefined' || this.is) {
                    render('#cid1', 0);
                } 

                form.on('select(cid1)', function(data) {
                    render('#cid2', data.value);
                    table.reload('LAY-app-content-list', {
                        where: {'category': {'cid1': data.value.split('-')[1]} }
                    });
                })
                form.on('select(cid2)', function(data) {
                    render('#cid3', data.value);
                    table.reload('LAY-app-content-list', {
                        where: {'category' : {'cid2': data.value.split('-')[1]} }
                    });
                })
                form.on('select(cid3)', function(data) {
                    table.reload('LAY-app-content-list', {
                        where: {'category' : {'cid3': data.value.split('-')[1] } }
                    });
                })
            }
        }
    }
    experts('yuefuli', {});
});
